package sanrenxing.dayEnd.backRepertoryTotal.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SecuritiesInformation;
import sanrenxing.dayEnd.backRepertoryTotal.service.impl.SecuritiesInformationBizImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能：债券信息控制器类
 * 编写者：蒋玲苹
 * 日期：210318
 * 版本：1.0
 */
@RestController
@RequestMapping("/securitiesInfo")
public class SecuritiesInformationController {

    @Autowired
    private SecuritiesInformationBizImpl securitiesInformationBiz;

    @GetMapping("/secur")
    public Map<String,Object>  queryAll(int page, int limit, SecuritiesInformation securitiesInformation){
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",securitiesInformationBiz.count(securitiesInformation));
        map.put("data",securitiesInformationBiz.queryAll(securitiesInformation,limit,(page-1)*limit));
        return map;
    }

    //添加数据
    @PostMapping("/secur")
    public String add(@RequestBody SecuritiesInformation securitiesInformation) {
        int rows=securitiesInformationBiz.add(securitiesInformation);
        //在添加债券的时候同时添加一行证券信息
        securitiesInformationBiz.addSec(securitiesInformation);
        return rows>0?"add success":"failure";
    }

    //删除数据
    @DeleteMapping("/secur/{str}")
    public String delete(@PathVariable String str){
        //调用业务层删除数据
        int rows=securitiesInformationBiz.delete(str);
        return rows>0?"delete success":"delete failure";
    }
    //修改数据
    @PutMapping("/secur")
    public String update(@RequestBody SecuritiesInformation securitiesInformation){
        //调用业务层修改数据
        int rows=securitiesInformationBiz.update(securitiesInformation);
        return rows>0?"update success":"update failure";
    }

}
